package DesignPattern

/*
将一个复杂对象的构建分离成多个简单对象的构建组合
*/

// Builder 申明生成器接口
type Builder interface {
	DoPart1()
	DoPart2()
	DoPart3()
}

// Director  演示如何使用Builder
type Director struct {
	builder Builder
}

// NewDirector 创建执行对象
func NewDirector(builder Builder) *Director {
	return &Director{
		builder: builder,
	}
}

// Construct 按照步骤进行构建
func (receiver *Director) Construct() {
	receiver.builder.DoPart1()
	receiver.builder.DoPart2()
	receiver.builder.DoPart3()
}

type BuilderOne struct {
	result string
}

func (receiver *BuilderOne) DoPart1() {
	receiver.result += "1"
}

func (receiver *BuilderOne) DoPart2() {
	receiver.result += "2"
}

func (receiver *BuilderOne) DoPart3() {
	receiver.result += "3"
}

func (receiver *BuilderOne) GetResult() string {
	return receiver.result
}

type BuilderTwo struct {
	result int
}

func (receiver *BuilderTwo) DoPart1() {
	receiver.result += 1

}

func (receiver *BuilderTwo) DoPart2() {
	receiver.result += 2
}

func (receiver *BuilderTwo) DoPart3() {
	receiver.result += 3
}

func (receiver *BuilderTwo) GetResult() int {
	return receiver.result
}
